#! /bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DIR="/root/ssh-drone-checker/"
DAEMON="dronecheck.sh"
PHPSCRIPT="dronecheck.php"

test -x ${DIR}${DAEMON} || exit 0

case "$1" in
  start)
	if [ `ps aux | grep -v grep | grep -c 'dronecheck.sh'` -eq 0 ] ; then
		echo 'Starting SSH Drone Checker...'
		cd $DIR
		./${DAEMON} 1>/dev/null 2>&1 &
	else
		echo 'SSH Drone Checker Already Running!'
	fi		
	;;
  stop)
	if [ `ps aux | grep -v grep | grep -c 'dronecheck.sh'` -eq 0 ] ; then
		echo 'SSH Drone Checker Not Running!'
	else
		killall -9 $DAEMON
		killall -9 $PHPSCRIPT
	fi
	;;
  restart|force-reload)
	$0 stop
	sleep 1
	$0 start
	;;
  *)
	echo "Usage: $0 {start|stop|restart|force-reload}" >&2
	exit 1
	;;
esac

exit 0
